// 用户信息数据
function createUserList() {
    return [
        {
            id: 1,
            avatar: 'https/127.0.0.1:8080/aaa.jpg',
            username: 'admin',
            password: '123456',
            roles: ['管理员'],
            desc: '管理员',
            routes: ['home'],
            token: 'Admin token',
        },
        {
            id: 2,
            avatar: 'https/127.0.0.1:8080/bbb.jpg',
            username: 'system',
            password: '111111',
            roles: ['系统管理员'],
            desc: '系统管理员',
            routes: ['home'],
            token: 'Admin token',
        }
    ]
}

export default [
    // 登录接口
    {
        url: '/api/user/login',
        method: 'post',
        response: ({body}) => {
            const {username, password} = body;
            const checkUser = createUserList().find(
                (item) => item.username === username && item.password === password,
            )
            if (!checkUser) {
                return {code: 201, data: {message: '账号密码不正确'}}

            }
            const {token} = checkUser
            return {code: 200, data: {token}}
        }
    },
    // 获取用户信息
    {
        url: '/api/user/info',
        method: 'get',
        response: ({request}) => {
            const token = request.headers.token;
            const checkUser = createUserList().find((item) => item.token === token)
            if (!checkUser) {
                return {code: 201, data: {message: '获取用户信息失败'}}

            }
            return {code: 200, data: {checkUser}}
        }
    }
]